package com.java.zhuiyun.api.order.mapper;

import com.java.zhuiyun.api.order.entity.Course;
import com.java.zhuiyun.api.order.entity.FrontDeskUser;
import com.java.zhuiyun.api.order.entity.MemberType;
import com.java.zhuiyun.api.order.entity.Orders;
import com.java.zhuiyun.api.order.model.OrderModel;
import com.java.zhuiyun.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @InterfaceName OrderMapper
 * @Description TODO
 * @Author wuwan
 * @Date 2023/8/25 9:48
 **/
@Mapper
public interface OrderMapper extends BaseMapper<Orders> {
    /*
    * @Author 订单号生成
    * @Description
    * @Date 2023/8/28 10:50
    * @Return
    * @param null
    */
    @Select("SELECT COUNT(*) AS count  FROM orders WHERE DATE(create_time) = CURDATE();")
    OrderModel numberGenerate();
    /*
    * @Author wuwan
    * @Description 查询出要购买的课程
    * @Date 2023/8/28 10:50
    * @Return
    * @param null
    */
    @Select("select * from course where id = #{cid};")
    Course getCourse(Integer cid);
    /*
    * @Author wuwan
    * @Description 查询出用户的信息
    * @Date 2023/8/28 10:51
    * @Return
    * @param null
    */
    @Select("select front_desk_member_time,front_desk_name,front_desk_member,front_desk_phone from front_desk_user where id=#{id}")
    FrontDeskUser userVip(Integer uid);
    /*
    * @Author wuwan
    * @Description 查询出会员的折扣力度
    * @Date 2023/8/28 10:51
    * @Return
    * @param null
    */
    @Select("select discount from member_type where id=#{mid}")
    MemberType getMemberType(Integer mid);
    /*
    * @Author wuwan
    * @Description 查询出所有订单的信息
    * @Date 2023/8/28 10:50
    * @Return
    * @param null
    */
    @Select("select * from orders where del_flag = 0")
    List<Orders> selectOrders();
    /*
     * @Author wuwan
     * @Description 查询出月卡会员的折扣
     * @Date 2023/8/28 10:51
     * @Return
     * @param null
     */
    @Select("select discount from member_type where id=1")
    MemberType getMemberTypeMounth();
    /*
    * @Author wuwan
    * @Description 查询用户是否购买此课程
    * @Date 2023/8/31 9:05
    * @Return
    * @param null
    */
    @Select("select order_name from orders where user_id = #{uid} and del_flag = 0")
    List<Orders> selectOrderName(Integer uid);
    /*
     * @Author wuwan
     * @Description 根据id查询用户信息z
     * @Date 2023/8/30 19:44
     * @Return
     * @param null
     */
    @Select("SELECT * FROM  orders WHERE  user_id = #{id}")
    List<Orders> selectAllOrders(Integer id);
    /*
     * @Author wuwan
     * @Description 定时任务清除超过两小时未支付订单
     * @Date 2023/8/15 16:24
     * @Return
     * @param null
     */
    @Update("update orders set del_flag = 1 WHERE create_time <= NOW() - INTERVAL 2 HOUR AND order_status = 1 AND del_flag = 0")
    Integer updateOrder();

    /*
     * @Author WX
     * @Description 查询单个记录
     * @Date 2023/9/2 10:45
     * @Return
     * @param null
     */
    @Select("SELECT * FROM orders WHERE  user_id = #{uid} AND course_id = #{cid} AND order_status = 0")
    Orders selectByTwoId(Integer uid, Integer cid);
    /*
    * @Author wuwan
    * @Description 查询用户的收藏
    * @Date 2023/9/19 10:16
    * @Return
    * @param null
    */
    @Select("select * from orders where user_id = #{uid} and course_id = #{cid};")
    Orders selorder(Integer cid, Integer uid);
}
